package com.wx.util;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PhoneUtils {

	private static Map<String, String> phonePrefix = new HashMap<String, String>();// 手机前缀
	static{// 1 移动 2 联通 3 电信
		phonePrefix.put("130","2");
		phonePrefix.put("131","2");
		phonePrefix.put("132","2");
		phonePrefix.put("133","3");
		phonePrefix.put("134","1");
		phonePrefix.put("135","1");
		phonePrefix.put("136","1");
		phonePrefix.put("137","1");
		phonePrefix.put("138","1");
		phonePrefix.put("139","1");
		phonePrefix.put("145","2");
		phonePrefix.put("147","1");
		phonePrefix.put("150","1");
		phonePrefix.put("151","1");
		phonePrefix.put("152","1");
		phonePrefix.put("153","3");
		phonePrefix.put("155","2");
		phonePrefix.put("156","2");
		phonePrefix.put("157","1");
		phonePrefix.put("158","1");
		phonePrefix.put("159","1");
		phonePrefix.put("1700","3");
		phonePrefix.put("1701","3");
		phonePrefix.put("1702","3");
		phonePrefix.put("1703","1");
		phonePrefix.put("1704","1");
		phonePrefix.put("1705","1");
		phonePrefix.put("1706","1");
		phonePrefix.put("1707","2");
		phonePrefix.put("1708","2");
		phonePrefix.put("1709","2");
		phonePrefix.put("173","3");
		phonePrefix.put("175","2");
		phonePrefix.put("176","2");
		phonePrefix.put("177","3");
		phonePrefix.put("178","1");
		phonePrefix.put("180","3");
		phonePrefix.put("181","3");
		phonePrefix.put("182","1");
		phonePrefix.put("183","1");
		phonePrefix.put("184","1");
		phonePrefix.put("185","2");
		phonePrefix.put("186","2");
		phonePrefix.put("187","1");
		phonePrefix.put("188","1");
		phonePrefix.put("189","3");
	}

	/**
	 * 手机号验证
	 * 
	 * @param str
	 * @return 验证通过返回true
	 */
	public static boolean isMobile(String str){

		boolean b = false;
		if(StringUtils.isEmpty(str)){
			return b;
		}
		Pattern p = null;
		Matcher m = null;
		p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$"); // 验证手机号
		m = p.matcher(str);
		b = m.matches();
		return b;
	}

	public static Map<String, String> getPhonePrefix(){

		return phonePrefix;
	}
}
